from django.db import models
import datetime
from django.utils import timezone

# Create your models here.
class Question(models.Model):
    question_text = models.CharField(max_length=201)#该问题的文本描述
    pub_date = models.DateTimeField('date published')#该问题的提交时间
    def __str__(self):
        return self.question_text
    def was_published_recently(self):
        return timezone.now()>self.pub_date >= timezone.now() - datetime.timedelta(days=1)#本日期大于当前日期减去一天，且小于当前日期，方为真

class Choice(models.Model):
    question = models.ForeignKey(Question, on_delete=models.CASCADE)#每一个选项都对应一个问题
    choice_text = models.CharField(max_length=200)#该选项的文本描述
    votes = models.IntegerField(default=0)#该选项的投票数
    def __str__(self):
        return self.choice_text


